//
//  LoginViewCell.m
//  ConscienceWorldPorject
//
//  Created by 孙海琛 on 2019/11/28.
//  Copyright © 2019 孙海琛. All rights reserved.
//
#define LoginOneCell @"LoginOneCell"
#define LoginTwoCell @"LoginTwoCell"


#import "LoginViewCell.h"
@interface LoginViewCell()
@property (weak, nonatomic) IBOutlet UIButton *verificationBtn;//验证码按钮
@property (weak, nonatomic) IBOutlet UITextField *verificationTextF;//验证码输入框

@property (weak, nonatomic) IBOutlet UILabel *titleLab;
@property (weak, nonatomic) IBOutlet UITextField *contentTextF;

@end


@implementation LoginViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self createUI];
}
- (void)createUI{
    ViewBorderRadius(_verificationBtn, 5, 1, [UIColor colorFromHexCode:@"2367DF"]);
    [_contentTextF addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    [_verificationTextF addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}

+ (instancetype)tempTableViewCellWith:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath model:(NSMutableArray *)arrayData{
    LoginModel *model = arrayData[indexPath.row];
    NSInteger index;//xib中第几个Cell
    NSString *identifier;//对应xib中设置的identifier
    if (![model.title isEqualToString:@"验 证 码:"]) {
        identifier = LoginOneCell;
        index = 0;
    }else
    {
        identifier = LoginTwoCell;
        index = 1;
    }
    LoginViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"LoginViewCell" owner:self options:nil] objectAtIndex:index];
    }
    if ([identifier isEqualToString:LoginTwoCell]) {
        cell.verificationTextF.tag = 10001;
    }else
    {
        cell.contentTextF.tag = indexPath.row+100;
    }
    return cell;
}

- (void)setModel:(LoginModel *)model
{
    _model = model;
    _titleLab.text = model.title;
    if (![model.title isEqualToString:@"验 证 码:"]) {
        _contentTextF.placeholder = model.holder;
    }else
    {
        _verificationTextF.placeholder = model.holder;
    }
}
- (void)textFieldDidChange:(UITextField *)textFiled
{
    _model.content = textFiled.text;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
